<?
/*
%%%copyright%%%
 * phpMyTicket - ticket reservation system
 * Copyright (C) 2004-2005 Anna Putrino, Stanislav Chachkov. All rights reserved.
 *
 * This file is part of phpMyTicket.
 *
 * This file may be distributed and/or modified under the terms of the
 * "GNU General Public License" version 2 as published by the Free
 * Software Foundation and appearing in the file LICENSE included in
 * the packaging of this file.
 *
 * Licencees holding a valid "phpmyticket professional licence" version 1
 * may use this file in accordance with the "phpmyticket professional licence"
 * version 1 Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 *
 * The "phpmyticket professional licence" version 1 is available at
 * http://www.phpmyticket.com/ and in the file
 * PROFESSIONAL_LICENCE included in the packaging of this file.
 * For pricing of this licence please contact us via e-mail to 
 * info@phpmyticket.com.
 * Further contact information is available at http://www.phpmyticket.com/
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Contact info@phpmyticket.com if any conditions of this licencing isn't 
 * clear to you.
 
 */
?>
<?
require_once("../includes/config/init_admin.php");
require_once ("admin/MenuAdmin.php");
require_once ("admin/AdminPage.php");
require_once ("page_classes/AUIBico.php");
require_once ("admin/FileView.php");


if(isset($_GET['download'])){
  global $_SHOP;
  require_once("classes/Organizer.php");
  require_once("functions/file_func.php");
    
  if(!$org=Organizer::load($_SHOP->organizer_id)){
    echo "<div class=error>".organizer_not_found."</div>";
    return;
  }
    
  $root=$_SHOP->user_dir."/".$org['organizer_nickname']."/";
  if(!file_exists($root) or !is_dir($root)){
    echo "<div class=error>".file_not_found."</div>";
    return;
  }
  $len_root=strlen($root);
    
  $pwd=$_SESSION['_SHOP_FILE_VIEW_pwd'][$org['organizer_nickname']];
  if(!isset($pwd)){
    $pwd=$root;
  }
  $download=$_GET['download'];

  if($download{0}=='/'){
      $new_download=realpath("$root/$download");
  }else{
      $new_download=realpath("$pwd/$download");
  }
  
  if(file_is_sub($root,$new_download)){
    file_download(dirname($new_download),basename($new_download));
    return;
  }
}

if(isset($_GET['view'])){
  global $_SHOP;
  require_once("classes/Organizer.php");
  require_once("functions/file_func.php");
    
  if(!$org=Organizer::load($_SHOP->organizer_id)){
    echo "<div class=error>".organizer_not_found."</div>";
    return;
  }
    
  $root=$_SHOP->user_dir."/".$org['organizer_nickname']."/";
  if(!file_exists($root) or !is_dir($root)){
    echo "<div class=error>".file_not_found."</div>";
    return;
  }
  $len_root=strlen($root);
    
  $pwd=$_SESSION['_SHOP_FILE_VIEW_pwd'][$org['organizer_nickname']];
  if(!isset($pwd)){
    $pwd=$root;
  }
  $view=$_GET['view'];

  if($view{0}=='/'){
      $new_view=realpath("$root/$view");
  }else{
      $new_view=realpath("$pwd/$view");
  }
  if(file_is_sub($root,$new_view)){
    file_view(dirname($new_view),basename($new_view));
    return;
  }
}


$body=new FileView();


//edit here your menu
$menu=new MenuAdmin();

// width=200 for menu ...Change it to your preferd width;
// 700 total table 
$bico=new AUIBico(150,700);
$bico->set("menu",$menu);
$bico->set("body",$body);
$page=new AdminPage();
$page->setTitle("Administration");
$page->set("body",$bico);
$page->draw();

?>
